<?php

class cntrlauth implements viewController {

	private $area;
	private $side;
	private $dependencies = array("JavaScript" => array() );
	private $pageName = "";
	
	public function __construct(user &$userObj){
		// Are we logging out?
		if($_GET['act'] == 'logout'){
			// Logout action
			session_destroy();
			header("Location: home");
			exit;
		}
	
		// Logging in
		if(isset($_POST['PBusernameField'], $_POST['PBpasswordField'])){	
			
			if( $userObj->auth($_POST['PBusernameField'], $_POST['PBpasswordField']) == true ){
				// Login Successful
				$_SESSION['userObject'] = serialize($userObj);
				header("Location: home");
				exit;
			} else {
				// Login unsuccessful. Show an error to the user.
				header("Location: error?id=2");
			}
		
		} else {
			header("Location: home");
		}
	}

	public function getSide(){
		return $this->side;
	}
	
	public function getArea(){
		return $this->area;
	}
	
	public function getDependencies(){
		return $this->dependencies;
	}

	public function getPageName(){
		return $this->pageName;
	}
	
	public function getTools(){
		return "";
	}
	
}

?>